<template>
  <div class="container">
    <a-card>
      <a-card-meta title="收货地址">
        <template #description
          >配置您的收货地址，所有商品将会寄送至此地址处进行鉴定。</template
        >
      </a-card-meta>
      <template v-if="dataSource">
        <div class="card-content flex">
          <div>
            <p>
              <img src="/image/icon1.png" alt="" srcset="" />
              <span>收件人：{{ dataSource.contactUserName }}</span>
            </p>
            <p>
              <img src="/image/icon2.png" alt="" srcset="" />
              <span>联系电话：{{ dataSource.contactMobile }}</span>
            </p>
            <p>
              <img src="/image/icon3.png" alt="" srcset="" />
              <span
                >收货地址：{{ dataSource.addressDetail }}</span
              >
            </p>
          </div>
          <a-button
            type="primary"
            @click="handleOpen('修改退货地址', dataSource)"
            >编辑</a-button
          >
        </div>
      </template>
      <div v-else class="empty">
        <img src="/image/icon4.png" alt="" srcset="" />
        <p>暂未添加收货地址</p>
        <a-button type="primary" @click="handleOpen('添加退货地址', dataSource)"
          >添加地址</a-button
        >
      </div>
    </a-card>
    <addressModal ref="addressModalRef" @refreshList="refreshList" />
  </div>
</template>
<script setup>
import addressModal from "./components/addressModal.vue";
import { getRecAddr } from "@/api/sysConfig";
import { ref, onMounted } from "vue";
const addressModalRef = ref(null);
function handleOpen(title, item) {
  addressModalRef.value.open(title, item);
}
function refreshList() {
  getRecAddrFn();
}
const dataSource = ref([]);
const getRecAddrFn = async () => {
  const result = await getRecAddr({});
  if (result.code === 200) {
    dataSource.value = result.data;
    console.log(dataSource.value);
  }
};
onMounted(() => {
  getRecAddrFn();
});
</script>
<style lang="less" scoped>
.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-content {
  padding: 24px;
  background-color: #f3f5f7;
  border-radius: 8px;
  margin-top: 24px;
  p {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    img {
      width: 20px;
      height: 20px;
    }
    span {
      font-size: 12px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #2b3453;
      line-height: 14px;
      margin-left: 8px;
    }
  }
  p:last-child {
    margin-bottom: 0;
  }
}
.empty {
  margin-top: 24px;
  background: #f3f5f7;
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  img {
    width: 56px;
  }
  p {
    font-size: 14px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #262e47;
    line-height: 16px;
    margin: 24px 0;
  }
}
</style>
